package server.business.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import server.business.mapper.BloodDiscardApplyMapper;
import server.business.pojo.BloodDiscardApply;
import server.business.service.BloodDiscardApplyService;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
* @author Galaxy
* @description 针对表【blood_discard_apply】的数据库操作Service实现
* @createDate 2022-11-08 12:46:23
*/
@Slf4j
@Service("bloodDiscardApplyService")
public class BloodDiscardApplyServiceImpl extends ServiceImpl<BloodDiscardApplyMapper, BloodDiscardApply>
    implements BloodDiscardApplyService{

    @Autowired
    private BloodDiscardApplyMapper bloodDiscardApplyMapper;
    @Override
    public Boolean setisDeletedById(Integer Id, Integer is_deleted) {
        LambdaUpdateWrapper<BloodDiscardApply> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(BloodDiscardApply::getId, Id);
        updateWrapper.set(BloodDiscardApply::getIsDeleted, is_deleted);
        int result = bloodDiscardApplyMapper.update(null, updateWrapper);
        System.out.println("result" + result);
        return true;
    }

    @Override
    public BloodDiscardApply findByApplyId(String  ApplyId) {
        QueryWrapper<BloodDiscardApply> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("apply_id",ApplyId);
        queryWrapper.select(BloodDiscardApply.class, info ->
                !info.getColumn().equals("gmt_create")
                        && !info.getColumn().equals("gmt_modified"));
        List<BloodDiscardApply> list = bloodDiscardApplyMapper.selectList(queryWrapper);
        log.info(String.valueOf(list));
        return list.get(0);
    }

    @Override
    public Boolean setisDeletedByApplyId(String applyId, Integer is_deleted) {
        LambdaUpdateWrapper<BloodDiscardApply> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(BloodDiscardApply::getApplyId, applyId);
        updateWrapper.set(BloodDiscardApply::getIsDeleted, is_deleted);
        int result = bloodDiscardApplyMapper.update(null, updateWrapper);
        System.out.println("result" + result);
        return true;
    }

    @Override
    public ArrayList<String> findDiscardApplyidById(ArrayList<Long> ids) {
        List<BloodDiscardApply> discardApply = bloodDiscardApplyMapper.selectBatchIds(ids);
        ArrayList<String> batchApplyidlist = new ArrayList<>();
        for(int i=0;i<discardApply.size();i++){
            batchApplyidlist.add(discardApply.get(i).getApplyId());
        }
        return batchApplyidlist;
    }

    @Override
    public ArrayList<String> findBloodIdList(ArrayList<Long> ids) {
        List<BloodDiscardApply> discardApply = bloodDiscardApplyMapper.selectBatchIds(ids);
        ArrayList<String> batchBloodidlist = new ArrayList<>();
        for(int i=0;i<discardApply.size();i++){
            batchBloodidlist.add(discardApply.get(i).getBloodId());
        }
        return batchBloodidlist;
    }

    @Override
    public String findSampleDiscardApplyidById(Integer id) {
        BloodDiscardApply discardApply = bloodDiscardApplyMapper.selectById(id);
        return discardApply.getApplyId();
    }

    @Override
    public String findSampleBloodIdById(Integer id) {
        BloodDiscardApply discardApply1 = bloodDiscardApplyMapper.selectById(id);
        return discardApply1.getBloodId();
    }
}




